package com.gitee.wsl.ext.collection


inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.flatMapToNullable(
    destination: C,
    transform: (T) -> Iterable<R>?,
): C? {
    for (element in this) {
        val list = transform(element) ?: return null
        destination.addAll(list)
    }
    return destination
}